package com.jk.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jk.dao.StaffDao;
import com.jk.entity.StaffEntity;
import com.jk.service.LoginService;

import com.jk.utils.Md5UUIDSaltUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class LoginServiceImpl extends ServiceImpl<StaffDao, StaffEntity> implements LoginService {
    @Autowired
    private StaffDao staffDao;

    @Override
    public StaffEntity findByUsername(String username) {
        //相当于select * from user where account='${username}'
        QueryWrapper<StaffEntity> wrapper=new QueryWrapper<>();
        wrapper.eq("account",username);
        //user即为查询结果
        return staffDao.selectOne(wrapper);
    }
    //修改密码
    @Override
    public void updatePwd(StaffEntity staff) {

        //加盐,并将加过盐的密码 和盐重新存入数据库中
        String salt = Md5UUIDSaltUtil.getSalt();
        //自己想搞什么搞什么 加密
        String mySalt=salt.substring(0,5);

        String password = Md5UUIDSaltUtil.createMd5Code(staff.getPassword()+mySalt);
        staff.setPassword(password);
        staff.setSalt(salt);

        staffDao.updateById(staff);
    }


}
